package com.easy.web.service.impl;

import com.easy.web.mapper.TeacherMapper;
import com.easy.web.model.Teacher;
import com.easy.web.model.TeacherExample;
import com.easy.web.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by wang0 on 2017/8/24.
 */
@Service
@Transactional
public class TeacherServiceImpl implements TeacherService{

    
    @Autowired
    private TeacherMapper teacherMapper;
    /**
     * 查询老师列表
     */
    @Override
    public List<Teacher> getTeacherList() {
        return getTeacherListDB();
    }

    /**
     * 新增老师
     *
     * @param teacher
     */
    @Override
    public List<Teacher> addTeacher(Teacher teacher) {
        teacherMapper.insert(teacher);
        return getTeacherListDB();
    }

    /**
     * 删除一个老师
     *
     * @param id
     */
    @Override
    public List<Teacher> delTeacher(String id) {
        teacherMapper.deleteByPrimaryKey(id);
        return getTeacherListDB();
    }

    /**
     * 更新老师信息
     *
     * @param teacher
     */
    @Override
    public List<Teacher> updateTeacher(Teacher teacher) {
        teacherMapper.updateByPrimaryKeySelective(teacher);
        return getTeacherListDB();
    }

    /**
     * 根据id查询老师
     *
     * @param id
     */
    @Override
    public Teacher queryTeacherById(String id) {
        return teacherMapper.selectByPrimaryKey(id);
    }


    public List<Teacher> getTeacherListDB() {
        TeacherExample teacherExample=new TeacherExample();
        teacherExample.setOrderByClause("create_time");
        return teacherMapper.selectByExample(teacherExample);
    }
    
}
